package cn.liu.jetpack_demo.components

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import cn.liu.jetpack_demo.ui.theme.color1
import cn.liu.jetpack_demo.ui.theme.color2

@Composable
fun GradientButton(
  text: String,
  textColor: Color,
  gradient: Brush,
  onClick: () -> Unit
) {
  Button(
    onClick = onClick,
    colors = ButtonDefaults.buttonColors(
      containerColor = Color.Transparent,
    ),
    shape = RoundedCornerShape(10.dp),
    elevation = null
  ) {
    Box(
      modifier = Modifier
        .background(gradient)
        .padding(horizontal = 16.dp, vertical = 8.dp),
      contentAlignment = Alignment.Center
    ) {
      Text(text = text, color = textColor)
    }
  }
}

@Preview(name = "GradientButton")
@Composable
private fun PreviewGradientButton() {
  GradientButton(
    text = "GradientButton",
    textColor = Color.White,
    gradient = Brush.horizontalGradient(colors = listOf(color1, color2)),
    onClick = {})
}